﻿using System;
using System.Threading.Tasks;
using Avalonia;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using AvaloniaUI.Modal.Services;
using AvaloniaUI.Modal.Animations;

namespace AvaloniaUI.Modal.Demo.ViewModels
{
    public partial class MainWindowViewModel : ViewModelBase
    {
        /// <summary>
        /// 上一次对话框结果
        /// </summary>
        [ObservableProperty]
        private string _lastResult = "尚未显示对话框";

        /// <summary>
        /// 显示消息对话框命令
        /// </summary>
        [RelayCommand]
        private async Task ShowMessageDialog()
        {
            var viewModel = new MessageDialogViewModel
            {
                Title = "确认操作",
                Message = "您确定要执行此操作吗？",
                OkText = "确定",
                CancelText = "取消",
                ShowCancel = true
            };

            var result = await Application.Current.ShowModalAsync<bool?>(viewModel);
            LastResult = $"消息对话框结果: {(result==true ? "确定" : "取消")}";
        }

        /// <summary>
        /// 显示输入对话框命令
        /// </summary>
        [RelayCommand]
        private async Task ShowInputDialog()
        {
            var viewModel = new InputDialogViewModel
            {
                Title = "请输入",
                Prompt = "请输入您的姓名:",
                Input = "",
                OkText = "确定",
                CancelText = "取消"
            };

            var result = await Application.Current.ShowModalAsync<string>(viewModel);
            LastResult = $"输入对话框结果: {(result != null ? result : "取消")}";
        }

        /// <summary>
        /// 显示自定义动画对话框命令
        /// </summary>
        [RelayCommand]
        private async Task ShowCustomAnimationDialog()
        {
            var viewModel = new MessageDialogViewModel
            {
                Title = "自定义动画",
                Message = "这是一个使用自定义动画的对话框。",
                OkText = "确定",
                CancelText = "取消",
                ShowCancel = true
            };

            var options = new ModalDialogOptions
            {
                CloseOnClickOverlay = true,
                CloseOnEscape = true,
                Animation = new ModalAnimation
                {
                    Duration = TimeSpan.FromMilliseconds(500),
                    Type = AnimationType.Scale
                }
            };

            var result = await Application.Current.ShowModalAsync<bool>(viewModel, options);
            LastResult = $"自定义动画对话框结果: {(result ? "确定" : "取消")}";
        }
    }
}
